namespace DataModels.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class DHISLink : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ReportDataSetElementsLinks",
                c => new
                    {
                        ReportDataSetLinkId = c.Int(nullable: false),
                        ReportIndicatorId = c.Int(nullable: false),
                        DataElementId = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => new { t.ReportDataSetLinkId, t.ReportIndicatorId, t.DataElementId })
                .ForeignKey("dbo.ReportDataSetLinks", t => t.ReportDataSetLinkId, cascadeDelete: true)
                .ForeignKey("dbo.ReportDataLocations", t => t.ReportIndicatorId, cascadeDelete: true)
                .Index(t => t.ReportDataSetLinkId)
                .Index(t => t.ReportIndicatorId);
            
            CreateTable(
                "dbo.ReportDataSetLinks",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ReportId = c.Int(nullable: false),
                        DataSetId = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Report", t => t.ReportId, cascadeDelete: true)
                .Index(t => t.ReportId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.ReportDataSetElementsLinks", "ReportIndicatorId", "dbo.ReportDataLocations");
            DropForeignKey("dbo.ReportDataSetElementsLinks", "ReportDataSetLinkId", "dbo.ReportDataSetLinks");
            DropForeignKey("dbo.ReportDataSetLinks", "ReportId", "dbo.Report");
            DropIndex("dbo.ReportDataSetLinks", new[] { "ReportId" });
            DropIndex("dbo.ReportDataSetElementsLinks", new[] { "ReportIndicatorId" });
            DropIndex("dbo.ReportDataSetElementsLinks", new[] { "ReportDataSetLinkId" });
            DropTable("dbo.ReportDataSetLinks");
            DropTable("dbo.ReportDataSetElementsLinks");
        }
    }
}
